package cn.wolfcode.crm.service.impl;


import cn.wolfcode.crm.domain.Car;
import cn.wolfcode.crm.mapper.CarMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICarService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CarServiceImpl implements ICarService {

	@Autowired
	private CarMapper carMapper;


	public List<Car> selectAll() {
		return carMapper.selectAll();
	}

	public PageResult query(QueryObject qo) {
		int count = carMapper.queryForCount(qo);
		if (count == 0) {
			return new PageResult(count, Collections.EMPTY_LIST);
		}
		List<Car> result = carMapper.queryForList(qo);
		return new PageResult(count, result);
	}

	public void saveOrUpdate(Car record) {
		if (record.getId() != null) {
			carMapper.updateByPrimaryKey(record);
		} else {
			carMapper.insert(record);
		}
	}

	public void deleteByPrimaryKey(Long id) {
		carMapper.deleteByPrimaryKey(id);
	}

	public Car selectByPrimaryKey(Long id) {
		return carMapper.selectByPrimaryKey(id);
	}

	@Override
	public Car selectCarByBillId(Long id) {
		return carMapper.selectCarByBillId(id);
	}

}
